package ru.gerunn.silent.callable;

import ru.gerunn.silent.exception.SilentReadMessageException;
import ru.gerunn.silent.exception.SilentWriteMessageException;
import ru.gerunn.silent.io.IOHandler;
import ru.gerunn.silent.io.Reader;
import ru.gerunn.silent.io.Writer;
import ru.gerunn.silent.message.Message;
import ru.gerunn.silent.message.MessageListener;

public class RW implements IOHandler {

	private final Reader reader;
	private final Writer writer;

	public RW(final Reader reader, final Writer writer) {
		this.reader = reader;
		this.writer = writer;
	}

	public Object call() throws SilentReadMessageException, SilentWriteMessageException {
		Message message;
		while ((message = reader.read()) != null) {
			writer.write(message);
		}
		return null;
	}

	public void addEventListener(MessageListener listener) {
	}

}
